interface EventBus {
  fnlists: Record<FnName, Array<Function>>;
  $on(name: FnName, fn: Function): void;
  $emit:(name: FnName) => void;
};

type FnName = string | number | symbol;

export default new (class Bus implements EventBus {
  public fnlists: Record<FnName, Array<Function>> = {};
  public $on(name: FnName, fn: Function) {
    let fnArr = this.fnlists[name] || [];
    fnArr.push(fn);
    this.fnlists[name] = fnArr;
  };
  public $emit(name: FnName, ...ags: any[]) {
    let FnArr = this.fnlists[name];
    FnArr.forEach(callback => {
      callback.apply(this, ags);
    });
  }
});